package com.wsoft.manager;

import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wsoft.dto.LogDto;
import com.wsoft.entity.SysLogEntity;
import com.wsoft.mapper.SysLogMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author z001
 * @Date 2024/11/19 08:14
 */
@Service
public class SysLogManager extends ServiceImpl<SysLogMapper, SysLogEntity> {

    /**
     * 列表查询
     * @param dto
     * @return
     */
    public List<SysLogEntity> list(LogDto dto){
        QueryWrapper<SysLogEntity> query = new QueryWrapper<>();
        query.lambda().like(StrUtil.isNotBlank(dto.getUrl()),SysLogEntity::getUrl,dto.getUrl())
                .like(StrUtil.isNotBlank(dto.getMethod()),SysLogEntity::getMethod,dto.getMethod())
                .eq(StrUtil.isNotBlank(dto.getType()),SysLogEntity::getType,dto.getType())
                .eq(ObjUtil.isNotNull(dto.getIsException()),SysLogEntity::getIsException,dto.getIsException())
                .ge(ObjUtil.isNotNull(dto.getRuntimeBegin()),SysLogEntity::getRuntime,dto.getRuntimeBegin())
                .le(ObjUtil.isNotNull(dto.getRuntimeEnd()),SysLogEntity::getRuntime,dto.getRuntimeEnd())
                .ge(StrUtil.isNotBlank(dto.getCreateTimeBegin()),SysLogEntity::getCreateTime,dto.getCreateTimeBegin())
                .le(StrUtil.isNotBlank(dto.getCreateTimeEnd()),SysLogEntity::getCreateTime,dto.getCreateTimeEnd())
                .orderByDesc(SysLogEntity::getCreateTime);

        return list(query);
    }
}
